
//注册
$(function(){
$("#zhuce").click(function(){  
 var name =  '模考用户'
  var phone = $("#phone").val();
  var exam_type = $("#examType").val();
  var yzm = $("#yzm").val();
  var city = $("#city").val(); 
   var counties = $("#counties").val();
 	 var isAgree = $("#isAgree").prop("checked");
 	/*来源*/
 	let dqinfo = $('#dqinfo').val()  
 	let qdinfo = $('#qdinfo').val() 
 	let xlinfo = $('#xlinfo').val() 
 	let grinfo = $('#grinfo').val()
 	
  if( name == '' ){   //验证名字是否为空
      alert('请填写名字');
      return false;
  }
 	if( city == '' ){
 	    alert('选择地区');
 	    return false;
 	}
 	if( counties == '' ){    
      alert('选择县区');
      return false;
  }
  if( phone == '' ){   //验证手机号是否为空
      alert('请填写手机号');
      return false;
  }
 	if(isAgree==false){
 		alert("请同意用户协议与隐私政策之后再提交信息!");
 		return false;
 	 }
 var reg=/^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/; //手机号正则 
  if(!reg.test(phone)){   //验证手机号是否正确
      alert('请填写正确的手机号！');
      return false;
  }
  if(yzm==''){   //验证码是否为空
      alert('验证码不能为空');
      return false;
  }
 	if(isAgree==false){
 		alert("请同意用户协议与隐私政策之后再提交信息!");
 		return false;
 	 }
	$.ajax({
		url: '//zg99.offcn.com/index/mokao/register?actid='+now_actid+'&callback=?',
		type: 'GET',
		dataType: 'jsonp',
		data: {
			name: name,
			phone: phone,
			yzm: yzm,
			city: city,
			counties:counties,
			isagree: isAgree,
			exam_type:exam_type,
			dqinfo:dqinfo,
			xlinfo:xlinfo,
			grinfo:grinfo,
			qdinfo:qdinfo
		},
		success: function(data) {
			if (data.status=="1") {
				nowTime = new Date();
		        last_mytimes=getMiao($('.nowtime').find('span').html());
		        timer=setInterval(oTime,1);
				$('.page_cover').hide();
                $('.container').hide();
				$('#username').val(name);
                $('#usernum').val(phone);
			} else {
				alert(data.msg);
			}
		}
	});
});


//获取验证码
$('#getyzm').click(function(){ 
	var phone=$('#phone').val();
	if(phone==''){   //验证手机号是否为空
		alert('请填写手机号');
		return false;
	}
	var reg=/^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/; //手机号正则 
	if(!reg.test(phone)){   //验证手机号是否正确
		alert('请填写正确的手机号！');
		return false;
	}
	$.ajax({
		url: '//zg99.offcn.com/index/mokao/sendmsg?actid='+now_actid+'&callback=?',
		type: 'GET',
		dataType: 'jsonp',
		data: {phone: phone},
		success: function(data) {
			if (data.status=="1") {
				alert('正在发送请稍后...');
				var sec = 120;
				$("#getyzm").text(sec+'s后重试');
				var timer = setInterval(function (){
					sec--;
					$("#getyzm").text(sec+'s后重试');
					if (sec<1) {
						$("#getyzm").text('获取验证码');
						clearInterval(timer);		
					}
				}, 1000);
			} else {
				if(data.status=="4" || data.msg=="请勿重复注册"){
					alert('您已注册,去登陆吧');
					$('#getyzm').show(0);
					$('#daojishi').hide(0);
					$('.container').find('.agileits').hide().eq(0).show();
					$('.bd_nav').find('span').removeClass('active').eq(0).addClass('active');
				}else{
					alert(data.msg);
				}
				
			}
		}
	});
	
});

//登录
$("#denglu").click(function(){ 
    var phone  = $("#loginPhone").val();
    if(phone==''){   //验证手机号是否为空
        alert('请填写手机号');
        return false;
    }
    var reg=/^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/; //手机号正则 
    if(!reg.test(phone)){   //验证手机号是否正确
        alert('请填写正确的手机号！');
        return false;
    }
    $.ajax({
        url: '//zg99.offcn.com/index/mokao/getphonestatus?actid='+now_actid+'&callback=?',
        type: 'GET',
        dataType: 'jsonp',
        data: {phone:phone},
        success: function(data) {
            if (data.status=="1") { 
				//console.log(data)
            	nowTime = new Date();
		        last_mytimes=getMiao($('.nowtime').find('span').html());
		        timer=setInterval(oTime,1);
				$('.page_cover').hide();
                $('.container').hide();
				$("#username").val(data.user.name);
				//console.log($("#username").val())
                $('#usernum').val(phone); 
            }if(data.status=="2"){ 
				alert("请未注册，再登录");
//					alert("请购买题库！");
//				window.location.href="//gz.zggqzp.com/zt/2020mtmk/";
				$('.container').find('.agileits').hide().eq(1).show();
				$('.bd_nav').find('span').removeClass('active').eq(1).addClass('active');
            }
        }
    });
});

});
//提交试卷
function  submitPc(event){
	var name   =  '模考用户';
	//console.log(name);
    var phone  = $("#usernum").val();
    var    exam_type  = now_type;
	var city = $("#city").val();
    var fenshu = $("#userscore").val();
    var userrecord = $("#userrecord").val(); 
    if ( name == '' ) {
        alert('请输入姓名');
        return false;
    }
    if (!phone) {
        alert('请输入手机号');
        return false;
    } 
	var phone_re=/^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/; //手机号正则 
    if (!phone_re.test(phone)) {
        alert('请输入正确的手机号');
        return false;
    }
	
	//写入答题记录
	$.getJSON('//zg99.offcn.com/index/mokao/writelogs?actid='+now_actid+'&callback=?', {name:name,phone: phone,exam_type:exam_type,city:city,fenshu:fenshu,userrecord:userrecord}, function (data) {});
	
	$.ajax({
		url: '//zg99.offcn.com/index/mokao/answer?actid='+now_actid+'&callback=?',
		type: 'GET',
		dataType: 'jsonp',
		data: {name:name,phone: phone,exam_type:exam_type,city:city,fenshu:fenshu,userrecord:userrecord},
		success: function(data) {
			if (data.status=="1") { 
				DispClose = false; 
				window.location.href="index_detail.html";
			} else {
				alert(data.msg);
			}
		}
	});
	

}   

